/*
 *@author: 陈旭光 , Chen XuG , chenxvguang19991@163.com
 */
    var iW = 0;
    var iH = 0;
    var num=0;
    var p2ani=true;
    var canScroll=true;
 window.onload=window.onresize=function(){
    iW = $(window).innerWidth();
    iH = $(window).innerHeight();
    $('#wrap>section').width(iW).height(iH);
    $('#wrap>section:nth-child(5)').width(iW).height(200);
    $('#wrap').css('display','block');
//鼠标滑动页面切换
    mouWheel(document, function(down) {
            if(canScroll){
                     canScroll=false;
                     setTimeout(function() {canScroll = true;},2000);
                     if(down){
                             if(num>0){
                                    num--;
                                   $('#wrap').animate({top:-iH*num+"px"},1000)}}
                     else{
                              if(num<$('#wrap>section').length-2){
                                      num++;
                                  $('#wrap').animate({top:-iH*num+"px"},1000)}
                           else if(num==$('#wrap>section').length-2){
                                       num++;
                                 $('#wrap').animate({top:-iH*(num-1)-200+"px"},600)}
                            }
                            move();
           }

            })  


//运动事件
            function move(){
                moveNav();
                moveP1();
                moveP2();
            }
//导航栏点击事件
            $('#nav li').each(function(){
                    $(this).click(
                        function(){
                            var index=$(this).index()
                            if(index!=num&&index!=3){
                                $('#wrap').animate({top:-iH*index+"px"},1000)
                            }
                            else if(index!=num&&index==3){
                                $('#wrap').animate({top:-iH*(index-1)-200+"px"},1000);
                            }
                            else{ return }
                            num=index;
                            move();
                        }

                   )
            })
//导航栏颜色改变事件
            function moveNav(){
                $('#nav li').removeClass('displayNow');
                $('#nav li:nth-child('+(num+1)+')').addClass('displayNow') 
            }

//p1动画效果
            //p1图片随鼠标移动效果            
            $('#p1').mousemove(function(e){
                var vx=(e.pageX-iW/2)/90;
                $('#bg1').css("background-position",(50+vx)+"% 50%")
               })
            //p1下拉箭头效果
            setTimeout(function(){$('#p1 img').removeClass("move2").addClass("move3")},2000);
           //动画
            setTimeout(function(){$('#p1 div:nth-child(2)').css('display','block')},100);
            function moveP1(){
                if(num==0){
                    setTimeout(function(){$('#p1 div:nth-child(2)').css('display','block')},200);
                }
                else{
                    setTimeout(function(){$('#p1 div:nth-child(2)').css('display','none')},1500)}
             }

//p2动画效果
            //星星绘画
            function creStars(){
                for(var i=0;i<25;i++){
                    var l=Math.floor(Math.random()*3+1);
                    var t=Math.random()*($('#star').height());
                    var w=Math.random()*($('#star').width());
                    var ele=$('<span>').css({display:'block',position:'relative',width:l+'px',height:l+'px',top:t+'px',left:w+'px',background:'#fff'});
                    if(l==3){ele.addClass('move6')};
                    ele.appendTo($('#star'));
                }} 
            //月亮绘画
                function creMoon(){
                    var ele=$('<span>').css({display:'block',position:'absolute',width:'90px',height:'90px',top:'700px',left:'100px',borderRadius:'100%',background:'#fff'}).addClass('move6');
                    var ele1=$('<span>').css({display:'block',position:'absolute',width:'86px',height:'86px',top:'700px',left:'116px',borderRadius:'100%',background:'#293039'});
                    ele.appendTo($('#star'));
                    ele1.appendTo($('#star'));
                }
            //动画
            function moveP2(){
                if(num==1){
                    creStars();
                    creMoon();
                    setTimeout(function(){$('#p2 img:last-of-type').css({bottom:'0px'});$('#star').css({top:'-200px'});},1000);
                    setTimeout(function(){$('#me0>div:nth-child(1)').css('display','block');$('#me2 h2').css('display','block')},2000);
                    setTimeout(function(){$('#me0>div:nth-child(3)').css('display','block');$('#me0>div:nth-child(2)').css('display','none');},3000);
                    if(p2ani){setTimeout(function(){$('#me0 #me1').css('display','block');$('#me2 ul li').css('display','block')},4000);p2ani=false}
                    else{setTimeout(function(){$('#me0 #me1').css('display','block');$('#me2 ul li').css('display','block')},1000)}
                }
                else{
                    setTimeout(function(){$('#me0 #me1').css('display','none');$('#me2 ul li').css('display','none')},1500)}
             }


//p3动画效果
            //p3 打开关闭demo方法
            $('#open').click(function(){
                $('#p3 iframe').css({transform:' perspective(6000px) rotateY(0)'})
                setTimeout(function(){$('#close').css('display','block')},2000)
            })
            $('#close').click(function(){
                $('#p3 iframe').css({transform:' perspective(6000px) rotateY(-90deg)'});
                $('#close').css('display','none')
            })


//鼠标换轮方法
        function mouWheel(obj, fn) {
                    if (window.navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
                        obj.addEventListener('DOMMouseScroll', fn1);
                    } else {
                        obj.addEventListener('mousewheel', fn1);
                    }

                    function fn1(ev) {
                        ev=ev||window.event;
                        var down = true;
                        if (ev.wheelDelta) {
                            down = ev.wheelDelta > 0 ? true : false;
                        } else {
                            down = ev.detail < 0 ? true : false;
                        }
                        typeof fn == 'function' && fn(down);
                        ev.preventDefault();
                    }
    }

        }